﻿using FairyGUI;

/// <summary>
/// 按钮组
/// </summary>
public class UICreateRoom_Buttons {

    GComponent _comp;
    int _curGame;
    UICreateRoom_Games _games;

    public UICreateRoom_Buttons(GComponent comp)
    {
        _curGame = 0;
        _comp = comp;
    }

    public void Init(UICreateRoom_Games games)
    {
        _games = games;

        GButton hengyangliuhuqiangBtn = _comp.GetChild("衡阳六胡抢按钮").asButton;
        hengyangliuhuqiangBtn.onChanged.Add(()=> {
            Show(hengyangliuhuqiangBtn, Constants.GAME_HENGYANGLIUHUQIANG);
        });

        GButton chenzhouBtn = _comp.GetChild("郴州按钮").asButton;
        chenzhouBtn.onChanged.Add(() => {
            Show(chenzhouBtn, Constants.GAME_CHENZHOUZIPAI);
        });

        // 默认选择 衡阳六胡抢
        _curGame = Constants.GAME_HENGYANGLIUHUQIANG;
        _comp.GetController("单选控制").selectedIndex = 0;
    }

    /// <summary>
    /// 显示游戏资料
    /// </summary>
    /// <param name="btn"></param>
    /// <param name="game"></param>
    void Show(GButton btn, int game)
    {
        AudioController.inst.PlayUIClickEffect();

        if ((_curGame == game) || (!btn.selected))
        {
            return;
        }

        _games.Show(_curGame, false);
        _curGame = game;
        _games.Show(_curGame, true);
    }
}
